package com.tour.controller;


import com.tour.config.ResponseWrapper;
import com.tour.entity.Poor;
import com.tour.service.impl.PoorServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lel
 * @since 2021-01-20
 */
@Api(tags = "贫困户管理")
@RestController
@RequestMapping("/app/poor")
public class PoorController {

    @Autowired
    PoorServiceImpl poorService;

    @ApiOperation("增加贫困人信息")
    @PostMapping("/addPoor")
    public ResponseWrapper addPoor(@RequestBody Poor poor){
        ResponseWrapper wrapper = poorService.addPoor(poor);
        return wrapper;
    }
    @ApiOperation("删除贫困人信息")
    @ApiImplicitParam(name = "poorId",value = "贫困人Id")
    @DeleteMapping("/delPoor")
    public ResponseWrapper delPoor(@RequestParam(name = "poorId") Integer poorId){
        ResponseWrapper wrapper = poorService.delPoor(poorId);
        return wrapper;
    }
    @ApiOperation("修改贫困人信息")
    @PutMapping("/updatePoor")
    public ResponseWrapper updatePoor(@RequestBody Poor poor){
        ResponseWrapper wrapper = poorService.updatePoor(poor);
        return wrapper;
    }
    @ApiOperation("模糊查询贫困人信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "poorContent",value = "搜索框搜索内容"),
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1")
    })
    @GetMapping("/findAllPoor")
    public ResponseWrapper findAllPoor(@RequestParam(name = "poorContent",required = false)String poorContent,
                                       @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                       @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum){
        ResponseWrapper wrapper = poorService.findAllPoor(poorContent,pageSize,pageNum);
        return wrapper;
    }
    @ApiOperation("查询单个贫困人信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "poorId",value = "贫困人id"),
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1")
    })
    @GetMapping("/findPoor")
    public ResponseWrapper findPoor(@RequestParam(name = "poorId")Integer poorId,
                                    @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                    @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum){
        ResponseWrapper wrapper = poorService.findPoor(poorId,pageSize,pageNum);
        return wrapper;
    }

}

